import re
import easygui as eg
from easygui import *
import tkinter as tk
from tkinter.filedialog import *
from tkinter.colorchooser import *
from tkinter.messagebox import *
from tkinter.scrolledtext import *
from tkinter.ttk import *
from tkinter import *
from PIL import *
import json
import sys
import os
import random
import time
import pyttsx3
from pyttsx3 import *
import socket

#声明窗口

def smwd(): 
    smt = "请阅读本协议后选择使用/不使用。\n本软件由个人开发，使用Python语言，使用以下库：\nTk/Tcl，\ntkinter，\neasygui，\nopenpyxl，\nPIL，\njson，\ntime，\nrandom，\nsys，\nos。\n本软件为开源软件，\n请勿用于非法用途，\n请勿进行非法编辑，\n造成损失概不负责!"
    sr = Tk()
    sr.title("商超系统 - 声明")
    sr.resizable(False, False)
    sr.attributes("-topmost", True)
    sr.attributes("-alpha", 1)
    sr.protocol("WM_DELETE_WINDOW", lambda:sys.exit(0))
    Label(sr, text="请阅读以下协议", font=("华文楷体", 20, "bold")).pack()
    Separator(sr).pack(fill="x", pady=5)
    smst = ScrolledText(sr, font=("黑体", 13))
    smst.insert("end", smt)
    smst.pack(fill="both")
    smst.config(state="disabled")
    Button(sr, text="同意", font=("华文楷体", 14), command=lambda:sr.destroy(), activebackground="#7FC8FF").pack(side="left", ipadx=160)
    Button(sr, text="拒绝", font=("华文楷体", 14), command=lambda:nt(), activebackground="#7FC8FF").pack(side="left", ipadx=160)
    def nt():
        showwarning("拒绝协议", "您选择拒绝本协议，请注意您的使用行为！")
        sr.destroy()
        print("用户拒绝协议")
        sys.exit(0)
    sr.mainloop()

smwd()

print(sys.platform)

if sys.platform == "win32":
    pass
else:
    msgbox(msg="请使用WindowsXP及以上版本系统！", title="Error: Operating System Type and Version Error", ok_button="确认", image=None, root=None)
    sys.exit(1)

print(tk.TkVersion)

class rt:
    teacher = pyttsx3.init()
    teacher.setProperty("rate", 125)
    teacher.setProperty("volume", 1)
    voices = teacher.getProperty('voices')
    teacher.setProperty('voice',voices[0].id)
    def __read__(text):
        rt.teacher.say(text=text)
        rt.teacher.runAndWait()

def readtext(self, text):
    self.after(0, rt.__read__, text)

class spobj:
    many = []
    spl = {}
    mn = 0

sp_steup = spobj
sp = sp_steup
spol = {"steup":sp_steup}

def jswt(inf):
    fileObj = open(fp, "w", encoding="UTF8")
    json.dump(inf, fileObj, ensure_ascii=False)
    fileObj.close()

def jsrd(k):
    fileObj = open(fp, "r", encoding="UTF8")
    inf = json.load(fileObj)
    inf = inf.get(k)
    fileObj.close()
    return inf

def jsrdall():
    fileObj = open(fp, "r", encoding="UTF8")
    inf = json.load(fileObj)
    fileObj.close()
    return inf

def jsad(k, inf):
    fileObj = open(fp, "r", encoding="UTF8")
    fi = fileObj
    fi[k] = inf
    fileObj.close()
    fileObj = open(fp, "w", encoding="UTF8")
    fileObj.write(fi)
    fileObj.close()

def jsmc(sp, mcs):
    fileObj = open(fp, "r", encoding="UTF8")
    inf = json.load(fileObj)
    fileObj.close()
    (inf[sp])["mccount"] = (inf[sp])["mccount"] + mcs
    fileObj = open(fp, "w", encoding="UTF8")
    json.dump(inf, fileObj, ensure_ascii=False)
    fileObj.close()

class js:
    def rd(url, code="UTF8"):
        fileObj = open(url, "r", encoding=code)
        inf = json.load(fileObj)
        fileObj.close()
        return inf
    def rds(data):
        inf = json.loads(data)
        return inf
    def wt(data, url, ea=False, code="UTF8"):
        fileObj = open(url, "w", encoding=code)
        json.dump(data, fileObj, ensure_ascii=ea)
        fileObj.close()
    def dp(data, ea=False):
        inf = json.dumps(data, ensure_ascii=ea)
        return inf

class menulambda:
    def strd():
        frrd.place(x=0, y=0, width=800, height=600)
        frwt.place_forget()
    def stwt():
        frwt.place(x=0, y=0, width=800, height=600)
        frrd.place_forget()

class spcf:
    def add(s):
        global cbl
        try:
            m = (cbl[s])["xmany"]
            if (s in sp.spl):
                sp.spl[s] = sp.spl[s] + 1
            else:
                sp.spl[s] = 1
            sp.many.append(m)
        except:
            pass
        spcf.jsm()
        print(sp.many)
        print(sp.spl)
    def dlt():
        try:
            sn = lb.curselection()
            for i in range(len(sn)):
                si = sn[i]
                spli = list(sp.spl.keys())[si]
                sp.spl[spli] = sp.spl[spli] - 1
                if sp.spl[spli] == 0:
                    del(sp.spll[spli])
                sp.many.pop(si)
                lb.delete(si)
        except:
            pass
        spcf.jsm()
        print(sp.many)
        print(sp.spl)
    def clear():
        sp.many = []
        sp.spl = {}
        print(sp.many)
        print(sp.spl)
        spcf.jsm()
        lb.delete(first=0, last=lb.size())
    def jsm():
        sp.mn = float(sum(sp.many))
        cjgsv.set(str(sp.mn))
        lb.delete(first=0, last=lb.size())
        for i in range(len(sp.spl)):
            i = list(sp.spl.keys())[i]
            lb.insert("end", f"{i} | {(cbl[i])['name']} | {(cbl[i])['xmany']} | {sp.spl[i]}")
        cjgsv.set(str(sp.mn))
    def ok():
        for i in range(len(sp.spl)):
            inf = jsrdall()
            xx = list(sp.spl.keys())[i]
            jsmc(xx, sp.spl[xx])
        spcf.clear()
        spcf.jsm()
        date.write(level=date.levels.info, from_="system", data=f"用户完成了一次交易，价格{sp.mn}元，商品:{sp.spl}")
    def jy():
        rt = Toplevel(root)
        rt.title("商超系统 - 价格确认")
        rt.geometry("600x680")
        rt.resizable(False, False)
        rt.attributes("-topmost", True)
        rt.attributes("-alpha", 1)
        ml = Label(rt, bg="SystemButtonFace", fg="#FFFF00000000", font=("黑体", 86), text=str(sp.mn), cursor="question_arrow", textvariable=cjgsv)
        ml.place(x=0, y=0, width=600, height=140)
        qrbt = Button(rt, text="确认", command=lambda:spcf.ok(), activebackground="#7FC8FF")
        qrbt.place(x=10, y=150, width=60, height=20)
        fzfr = Labelframe(master=rt, text="现金收银辅助")
        fzfr.place(x=0, y=180, width=600, height=500)
        fzfrin = Labelframe(master=fzfr, text="TA给了你多少钱")
        fzfrin.place(x=0, y=0, width=300, height=400)
        fzfrot = Labelframe(master=fzfr, text="你给了TA多少钱")
        fzfrot.place(x=300, y=0, width=300, height=400)
        XXL = [("1角", "#4C3F3C", "#E5CBBB", "#AEA896", 0.1), 
               ("5角", "#6E3F3C", "#B59B9A", "#9F8D76", 0.5), 
               ("1元", "#3F4030", "#BDC3AD", "#B9A17C", 1), 
               ("5元", "#43364F", "#D1C1A6", "#9B9AC0", 5), 
               ("10元", "#3E465A", "#ADAFBC", "#9C8598", 10), 
               ("20元", "#4B3427", "#DDBDA1", "#AF9E96", 20), 
               ("50元", "#3D5448", "#95C4AD", "#B5A998", 50), 
               ("100元", "#9B162A", "#F2ABBC", "#DB6A7E", 100)]
        def upd():
            global otxxspbd
            global inxxspbd
            jg = 0.0
            for i in range(len(otxxspbd)):
                k = (XXL[i])[0]
                v = otxxspbd[k]
                b = (XXL[i])[4]
                j = int(v.get())
                jg = jg - (j * b)
            for i in range(len(inxxspbd)):
                k = (XXL[i])[0]
                v = inxxspbd[k]
                b = (XXL[i])[4]
                j = int(v.get())
                jg = jg + (j * b)
            ccjgsv.set(str(sp.mn-jg))
            fcjgsv.set(str(-1*(sp.mn-jg)))
            return True
        global inxxspbd
        global otxxspbd
        inxxspbd = {}
        for i in range(len(XXL)):
            name = (XXL[i])[0]
            fg = (XXL[i])[1]
            bg = (XXL[i])[2]
            abg = (XXL[i])[3]
            Label(master=fzfrin, text=name, anchor=W, fg=fg).place(x=10, y=10+(30*i), width=50, height=20)
            inxxspbd[name] = Spinbox(master=fzfrin, from_=0, to=2**63-1, increment=1, state="readonly", fg=fg, bg=bg, selectbackground=abg, selectforeground=fg)
            inxxspbd[name].place(x=60, y=10+(30*i), width=230)
        otxxspbd = {}
        for i in range(len(XXL)):
            name = (XXL[i])[0]
            fg = (XXL[i])[1]
            bg = (XXL[i])[2]
            abg = (XXL[i])[3]
            Label(master=fzfrot, text=name, anchor=W, fg=fg).place(x=10, y=10+(30*i), width=50, height=20)
            otxxspbd[name] = Spinbox(master=fzfrot, from_=0, to=2**63-1, increment=1, state="readonly", fg=fg, bg=bg, selectbackground=abg, selectforeground=fg)
            otxxspbd[name].place(x=60, y=10+(30*i), width=230)
        ccjgsv = StringVar()
        fcjgsv = StringVar()
        cml = Label(fzfr, fg="#8F008F", font=("黑体", 20), cursor="question_arrow", textvariable=ccjgsv, anchor=W, text="The Debug Text")
        cml.place(x=100, y=400, width=500, height=50)
        cml = Label(fzfr, fg="#008F00", font=("黑体", 17), cursor="question_arrow", textvariable=fcjgsv, anchor=W, text="The Debug Text")
        cml.place(x=100, y=450, width=500, height=30)
        upbt = Button(master=fzfr, text="update", command=lambda:upd(), activebackground="#7FC8FF", font=18)
        upbt.place(x=10, y=410, width=80, height=45)
        print(inxxspbd)
        print(otxxspbd)
    class obj:
        def __update__():
            spcf.jsm()
        def cut(objname):
            global spol
            global sp
            sp = spol[objname]
            spcf.obj.__update__()
        def create(objname):
            global spol
            if objname == "create":
                msgbox(msg="'steup'商品实例不能用'create'作为名字！", title="Error: 'sp'objectError", ok_button="确认", image=None, root=None)
                return 0
            spol[objname] = spobj
        def delete(objname):
            global spol
            if objname == "steup":
                msgbox(msg="'steup'商品实例不可删除！", title="Error: 'sp'objectError", ok_button="确认", image=None, root=None)
                return 0
            else:
                del(spol[objname])
            spcf.obj.__update__()
        def clear():
            global sp_steup
            global sp
            global spol
            sp_steup = spobj
            sp = sp_steup
            spol = {"steup":sp_steup}
            spcf.obj.__update__()
        def cz():
            ks = spol.keys()
            try:
                key = choicebox(msg="", title="商超系统 - 选择操作的值", choices=ks, preselect=0, callback=None, run=True)
                doing = {"创建/修改": "create", 
                         "删除": "delete",
                         "清除": "clear", 
                         "切换": "go to"
                }
                mood = doing[choicebox(msg="", title="你要干什么？", choices=doing.keys(), preselect=0, callback=None, run=True)]
                if mood == "create":
                    spcf.obj.create(objname=str(enterbox(msg="", title="商超系统 - 输入", default="objname", strip=True, image=None, root=None)))
                elif mood == "delete":
                    spcf.obj.delete(objname=key)
                elif mood == "clear":
                    spcf.obj.clear()
                elif mood == "go to":
                    spcf.obj.cut(objname=key)
            except:
                pass

def tkupdate():
    global cbl
    cbl = jsrdall()
    spcf.jsm()

class ex:
    def sj():
        inf = jsrdall()
        exsjfp = asksaveasfilename(filetypes=[("Microsoft Execl Files 2007+", "*.xlsx")], parent=root)
        l2inf = []
        for i in range(len(inf)):
            ik = list(inf.keys())[i]
            l2inf.append([ik, (inf[ik])["name"], (inf[ik])["many"], (inf[ik])["xmany"], (inf[ik])["allcount"], (inf[ik])["mccount"]])
        write_xlsx_excel(exsjfp, "Sheet", l2inf)
        date.write(level=date.levels.info, from_="system", data=f"用户进行了一次商品配置导出，json文件：{fp}, xlsx文件：{exsjfp}, json->xlsx")
    def rd():
        ph = askopenfilename(filetypes=[("Microsoft Execl Files 2007+", "*.xlsx")], parent=root)
        data = read_xlsx_excel(ph, "Sheet")
        print(data)
        inf = {}
        for sprow in data:
            inf[sprow[0]] = {"name": str(sprow[1]), "many": float(sprow[2]), "xmany": float(sprow[3]), "allcount": int(sprow[4]), "mccount": int(sprow[5])}
        jswt(inf)
        date.write(level=date.levels.info, from_="system", data=f"用户进行了一次商品配置导入，json文件：{fp}, xlsx文件：{ph}, xlsx->json")

def write_xlsx_excel(url, sheet_name, two_dimensional_data):
    import openpyxl
    workbook = openpyxl.Workbook()
    sheet = workbook.active
    sheet.title = sheet_name
    for i in range(0, len(two_dimensional_data)):
        for j in range(0, len(two_dimensional_data[i])):
            sheet.cell(row=i + 1, column=j + 1, value=str(two_dimensional_data[i][j]))
    workbook.save(url)
    print("写入成功")

def read_xlsx_excel(url, sheet_name):
    import openpyxl
    workbook = openpyxl.load_workbook(url)
    sheet = workbook.active
    data = []
    for row in sheet.rows:
        da = []
        for cell in row:
            da.append(cell.value)
        data.append(da)
    workbook.close()
    return data

class date:
    class levels:
        debug = 0
        info = 1
        warn = 2
        error = 3
        fatal = 4
    def write(level, data, from_, time=time.strftime("%Y/%m/%d %H:%M:%S")):
        import openpyxl
        from openpyxl.styles import Font, NamedStyle
        lil = ["debug", "info", "warn", "error", "fatal"]
        ydt = read_xlsx_excel(url=dfp, sheet_name="date")
        if level == 0:
            font = Font(size=11, italic=False,bold=False,color="11bb11",name='Calibri')
        elif level == 1:
            font = Font(size=11, italic=False,bold=False,color="000000",name='Calibri')
        elif level == 2:
            font = Font(size=11, italic=False,bold=False,color="999900",name='Calibri')
        elif level == 3:
            font = Font(size=11, italic=False,bold=False,color="bf6f00",name='Calibri')
        elif level == 4:
            font = Font(size=11, italic=False,bold=False,color="ff1010",name='Calibri')
        workbook = openpyxl.Workbook(dfp)
        zl = ["A", "B", "C", "D"]
        da = [time, lil[level], from_, data]
        sheet = workbook["date"]
        for i in zl:
            sheet[f"{i}{len(ydt)}"].font(font)
            sheet[f"{i}{len(ydt)}"] = da[zl.index(i)]
        workbook.save(dfp)
    def clear():
        write_xlsx_excel(url=dfp, sheet_name="date", two_dimensional_data=[["time", "level", "from", "data"]])


class tm:
    def a50():
        root.config(bg="SystemButtonFace")
        frrd.config(bg="SystemButtonFace")
        frwt.config(bg="SystemButtonFace")
        lb.config(bg="#FFFFFF")
        root.attributes("-alpha", 0.5)
    def a80():
        root.config(bg="SystemButtonFace")
        frrd.config(bg="SystemButtonFace")
        frwt.config(bg="SystemButtonFace")
        lb.config(bg="#FFFFFF")
        root.attributes("-alpha", 0.8)
    def a100():
        root.config(bg="SystemButtonFace")
        frrd.config(bg="SystemButtonFace")
        frwt.config(bg="SystemButtonFace")
        lb.config(bg="#FFFFFF")
        root.attributes("-alpha", 1)

zncbl = {}

class zl:
    def znlx():
        lx = Toplevel(root)
        lx.title("商超系统 - 智能联想")
        lx.geometry("580x530")
        lx.resizable(False, False)
        lx.attributes("-topmost", True)
        lx.attributes("-alpha", 1)
        def upd():
            lxlb.delete(first=0, last=lxlb.size())
            global zncbl
            zncbl = {}
            for i in cbl.keys():
                if lxer.get() in i:
                    lxlb.insert("end", str(f"{i} | {(cbl[i])['name']}"))
                    zncbl[i] = str(f"{i} | {(cbl[i])['name']}")
            return True
        lxer = Entry(lx, selectforeground="#000000", selectbackground="#7FC8FF")
        lxsb = Scrollbar(lx)
        lxsb.place(x=510, y=20, width=15, height=510)
        lxlb = Listbox(lx, yscrollcommand=lxsb.set)
        lxsb.config(command=lxlb.yview)
        lxlb.place(x=0, y=20, width=565, height=510)
        lxer.place(x=0, y=0, width=440, height=20)
        def xzst():
            global zncbl
            lxer.delete(0, len(lxer.get()))
            t = lxlb.curselection()
            t = t[0]
            ks = []
            for i in zncbl.keys():
                ks.append(i)
            t = ks[t]
            lxer.insert(0, t)
            upd()
        lxlb.bind("<<ListboxSelect>>", lambda e:xzst())
        def lxad():
            spcf.add(lxer.get())
        lxbt = Button(lx, text="Add", activebackground="#7FC8FF", command=lambda:lxad())
        lxbt.place(x=440, y=0, width=40, height=20)
        lxbt = Button(lx, text="Update", activebackground="#7FC8FF", command=lambda:upd())
        lxbt.place(x=480, y=0, width=80, height=20)
        upd()
        #cbl[list(lxlb.curselection())[0]]

class sd:
    def si():
        ix = Toplevel(root)
        ix.title("商超系统 - 设置")
        ix.geometry("700x200")
        ix.resizable(False, False)
        ix.attributes("-topmost", True)
        ix.attributes("-alpha", 1)
        def ner(event):
            if (event.keysym).isdigit():
                slb.config(state="normal")
                slb.insert(index="end", string=event.keysym)
                slb.config(state="readonly")
            elif event.keycode == 8:
                slb.config(state="normal")
                i = slb.get()
                i = i[0:(len(i)-2)]
                slb.delete(0, "end")
                slb.insert(0, i)
                slb.config(state="readonly")
            elif event.keycode == 13:
                i = slb.get()
                slb.config(state="normal")
                slb.delete(0, "end")
                slb.config(state="readonly")
                i = int(i)
                ii = js.rd(ifp)
                ii["sp_low_bj"] = i
                js.wt(data=ii, url=ifp)
        slb = Entry(ix, selectforeground="#000000", selectbackground="#7FC8FF")
        slb.place(x=10, y=10, width=150, height=20)
        slb.bind("<Key>", ner)
        slb.config(state="readonly")

class help:
    def wy():
        msgbox(msg="请找作者索要外国版程序！\n\nPlease ask the author for a foreign version of the program!\n\n作者に外国版プログラムを要求してください！\n\n저자를 찾아 외국판 절차를 요청하십시오!", title="商超系统 - 关于", ok_button="确认", image=None, root=None)

class linkobj:
    class udp:
        server = {}
        client = {}
        def update():
            linkobj.udp.server["default"] = {}
            linkobj.udp.server["default"] = linkobj.udp.server
            linkobj.udp.client["default"] = {}
            linkobj.udp.client["default"] = linkobj.udp.client
        def add(self, ip, port, type):
            if type == "server":
                linkobj.udp.server[ip] = {}
                linkobj.udp.server[ip][port] = self
            elif type == "client":
                linkobj.udp.client[ip] = {}
                linkobj.udp.client[ip][port] = self
        def remove(ip, type, port=-1):
            if type == "server":
                if port == -1:
                    for i in linkobj.udp.server[ip].values():
                        i.close()
                    del linkobj.udp.server[ip]
                else:
                    linkobj.udp.server[ip][port].close()
                    del linkobj.udp.server[ip][port]
            elif type == "client":
                if port == -1:
                    for i in linkobj.udp.client[ip].values():
                        i.close()
                    del linkobj.udp.client[ip]
                else:
                    linkobj.udp.client[ip][port].close()
                    del linkobj.udp.clientr[ip][port]
        def clear():
            linkobj.udp.server = {}
            linkobj.udp.client = {}
        def get(type, port=-1 , ip="default"):
            if type == "server":
                if port == -1:
                    return [ip, port, linkobj.udp.server[ip]]
                else:
                    return [ip, port, linkobj.udp.server[ip][port]]
            elif type == "client":
                if port == -1:
                    return [ip, linkobj.udp.client[ip]]
                else:
                    return [ip, port, linkobj.udp.client[ip][port]]

class bd:
    def udp():
        skw = Toplevel(root)
        skw.title("商超系统 - UDP")
        skw.geometry("500x300")
        skw.resizable(False, False) 
        sk = Button(skw, text="通信", command=lambda:bd.udpsk())
        sk.place(x=10, y=10, width=100, height=30)  
        sk = Button(skw, text="通信套接字", command=lambda:bd.udpck())
        sk.place(x=120, y=10, width=100, height=30)  
    def udpsk():
        skw = Toplevel(root)
        skw.title("商超系统 - UDP通信")
        #skw.resizable(False, False)
        sendbt = Button(skw, text="发送", command=lambda:send())
        sendbt.place(x=10, y=10, width=100, height=30)
        def send():
            bd.udpapi.send(self=0, data=114514, ip="127.0.0.1", port=0)
    def udpck():
        skw = Toplevel(root)
        skw.title("商超系统 - UDP通信")
        #skw.resizable(False, False)
        sl = Listbox(skw)
        sl.place(x=10, y=10, width=200, height=200)
        eip = Entry(skw)
        eip.place(x=220, y=10, width=150, height=20)
        eport = Entry(skw)
        eport.place(x=220, y=40, width=150, height=20)
        st = StringVar()
        st.set("server")
        srbt = Radiobutton(skw, text="服务端", variable=st, value="server")
        srbt.place(x=220, y=70, width=100, height=20)
        crbt = Radiobutton(skw, text="客户端", variable=st, value="client")    
        crbt.place(x=220, y=130, width=100, height=20)
        def add():
            linkobj.udp.add(self=socket.socket(socket.AF_INET, socket.SOCK_DGRAM), ip=eip.get(), port=int(eport.get()), type=st.get())
            sl.insert("end", f"{eip.get()}:{eport.get()}:{st.get()}")  
        def remove():
            s = (sl.curselection()[0]).split(":")
            linkobj.udp.remove(ip=s[0], type=s[2], port=int(s[1]))
            sl.delete(sl.curselection())
        addbt = Button(skw, text="添加", command=add())
        addbt.place(x=10, y=220, width=100, height=30)  
        removebt = Button(skw, text="删除", command=lambda:remove())
        removebt.place(x=120, y=220, width=100, height=30)  
    class udpapi:
        def recv(self, size=1024):
            return (self.recvfrom(size)).decode()
        def send(self, data, ip, port):
            self.sendto(data.encode(), (ip, port))
        def getname(self):
            return self.getsockname()
        def close(self):
            self.close()
        
        



#Tk窗口

root = Tk()
root.title("商超系统")
root.geometry("800x600")
root.resizable(False, False)
root.attributes("-topmost", True)
root.attributes("-alpha", 1)
root.protocol("WM_DELETE_WINDOW", lambda:root.destroy())
root.attributes("-transparentcolor", "#7F7F7F")

fp = askopenfilename(filetypes=[("JSON Files", ".json")], parent=root, title="商品配置")
ifp = askopenfilename(filetypes=[("JSON Files", ".json")], parent=root, title="设置配置")
dfp = asksaveasfilename(filetypes=[("Microsoft Execl Files 2007+", "*.xlsx")], parent=root, title="日志配置")

menu = Menu(root)

root.config(menu=menu)

fm = Menu(menu, title="操作")

menu.add_cascade(label="操作", menu=fm)

fm.add_command(label="收银", command=lambda:menulambda.strd())
fm.add_command(label="商超实例", command=lambda:spcf.obj.cz())
fm.add_command(label="写入", command=lambda:menulambda.stwt())

fm.add_separator()

simu = Menu(fm,title="设置")

fm.add_cascade(label="设置", menu=simu)

fm.add_separator()

fm.add_command(label="exit", command=lambda:root.destroy())

simu.add_command(label="置顶", command=lambda:root.attributes("-topmost", True))
simu.add_command(label="取消置顶", command=lambda:root.attributes("-topmost", False))

simu.add_separator()

simu.add_command(label="防关闭", command=lambda:root.protocol("WM_DELETE_WINDOW", lambda:msgbox(msg="已触发防关闭", title="", ok_button="确认", image=None, root=None)))
simu.add_command(label="取消防关闭", command=lambda:root.protocol("WM_DELETE_WINDOW", lambda:root.destroy()))

simu.add_separator()

simu.add_command(label="透明", command=lambda:tm.a50())
simu.add_command(label="半透明", command=lambda:tm.a80())
simu.add_command(label="不透明", command=lambda:tm.a100())

simu.add_separator()

simu.add_command(label="更多", command=lambda:sd.si())

menu.add_command(label="刷新", command=lambda:tkupdate())

gm = Menu(menu)

menu.add_cascade(label="关于我们", menu=gm)

gm.add_command(label="声明协议", command=lambda:smwd())
gm.add_command(label="关于作者", command=lambda:msgbox(msg="作者：\n\n张程皓\n\n联系方式：\n\nphone:18119490768\n\n微信:vxid_debjq3w2372p22", title="关于作者", ok_button="确认", image=None, root=None))
gm.add_command(label="关于软件", command=lambda:msgbox(msg="商超系统\n\n版本：1.0\n\n开发语言：Python\n\n开发工具：Tkinter\n\n开发环境：Windows 10\n\n开发作者：张程皓\n\n联系方式：18119490768\n\n给作者加个鸡腿吧:) 球球了", title="关于软件", ok_button="确认", image=None, root=None))
gm.add_separator()
bdmenu = Menu(gm, title="beta预发布测试功能")
gm.add_cascade(label="beta预发布测试功能",menu=bdmenu)

#beta预发布测试功能

bdmenu.add_command(label="联网通信UDP", command=lambda:bd.udp())

#stoped

frrd = Labelframe(root, text="收银")
frwt = Labelframe(root, text="写入")

dm = Menu(menu, title="Debug(开发人员专用)")
menu.add_cascade(label="Debug(开发人员专用)", menu=dm)

usermode = (js.rd(ifp))["user"]
if usermode == "system" or usermode == "debug":
    dm.add_command(label="开发功能还没做好......")
elif usermode == "admin":
    dm.add_command(label="看啥看，你还真当自己是开发人员了！")
elif usermode == "user":
    dm.add_command(label="看啥看，你就一用户，搞什么开发！")
elif usermode == "bin":
    dm.add_command(label="看啥看，你就一访客还好意思乱点！")
else:
    dm.add_command(label="账户都出错了，去叫开发者呀！愣着干啥！")

menu.add_command(label="My mother tongue is not Chinese.", command=lambda:help.wy())

# 收银LabelFrame

cb = StringVar()
cbl = jsrdall()
cbbox = Entry(frrd, selectforeground="#000000", selectbackground="#7FC8FF", textvariable=cb)
cbbox.grid(row=0, column=0, padx=10, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=5)

cbbmu = Menu(frrd, title="你要做什么", name="你要做什么")
cbbmu.add_command(label="智能联想", accelerator="Ctrl+M", command=lambda:zl.znlx())

cbbox.bind("<Button-3>", lambda e:cbbmu.post(e.x_root, e.y_root))
cbbmu.bind("<Control-m>", lambda e:zl.znlx())

def spadd():
    spcf.add(cbbox.get())

adbt = Button(frrd, text="添加", activebackground="#7FC8FF")
adbt.grid(row=0, column=5, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)
adbt.bind("<Button-1>", lambda e:spadd())

debt = Button(frrd, text="删除", activebackground="#7FC8FF")
debt.grid(row=1, column=0, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)
debt.bind("<Button-1>", lambda e:spcf.dlt())

clbt = Button(frrd, text="清空", command=spcf.clear, activebackground="#7FC8FF")
clbt.grid(row=2, column=0, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)

jsbt = Button(frrd, text="结算", command=spcf.jsm, activebackground="#7FC8FF")
jsbt.grid(row=0, column=6, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)

lb = Listbox(frrd, width=50, height=30, selectmode="multiple", exportselection=False, selectbackground="#7FC8FF", selectforeground="#000000")
sb = Scrollbar(frrd)

lb.grid(row=1, column=1, padx=10, pady=0, rowspan=40, columnspan=26)
sb.grid(row=1, column=27, padx=0, pady=0, rowspan=1, columnspan=1, sticky="s")

lb.config(yscrollcommand=sb.set)
sb.config(command=lb.yview)

jsbt = Button(frrd, text="完成支付", command=lambda:spcf.jy(), activebackground="#7FC8FF")
jsbt.grid(row=0, column=7, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)

cjgsv = StringVar()

#写入LabelFrame

sjbt = Button(frwt, text="导出配置", command=lambda:ex.sj(), activebackground="#7FC8FF")
sjbt.grid(row=0, column=0, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=2)

rdbt = Button(frwt, text="导入配置", command=lambda:ex.rd(), activebackground="#7FC8FF")
rdbt.grid(row=0, column=2, padx=0, pady=0, ipadx=0, ipady=0, rowspan=1, columnspan=1)

#事件循环

root.mainloop()

"""
作者：张程皓
联系方式：18119490768
声明：本软件为开源软件，转载时请注明出处，禁止用于商业用途。
"""
